/**
 * 消息
 * 
 * 参数：
 * 	1. msg_type：消息类型
 * 			a. wokflow：工作流消息
 *  2. options：参数对象
 *  		a. refresh：是否由ajax刷新，frequency：ajax刷新频率（分钟）
 */
(function($){
	$.fn.message = function(msg_type,options){
		options = $.extend($.fn.message.defaults, options?options:{});
		
		var obj = $(this);
		
		function workflow_ajax_refresh(){
			if(options.url){
				$.get(options.url, function(data){
					if(data && data.total && data.total>0){
						obj.html(data.total);
					}
				}, "json");
			}
		}
		
		function workflow(){
			if(options.refresh && options.frequency>0){
				setTimeout(workflow_ajax_refresh, 5000);
				setInterval(workflow_ajax_refresh, options.frequency*60000);
			}else{
				
			}
		}
		
		
		switch (msg_type) {
			case "workflow":
				workflow();
				break;
	
			default:
				break;
		}
	};
	
	$.fn.message.defaults = {
			refresh: true,
			frequency: 5,
			url: ""
		};
})(jQuery);